﻿using System;
using System.Linq;
using Baby.GrowUp.Model;
using Baby.GrowUp.Web.Admin.Base;

namespace Baby.GrowUp.Web.Admin
{
    public partial class AddAlbum : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void SaveAlbum(object sender, EventArgs e)
        {
            string fileName = imgCoverPath.FileName;
            string imgType = fileName.Split('.').Last();
            fileName = Guid.NewGuid() + "." + imgType;
            string fullPath = Server.MapPath("~/upload/") + fileName;
            imgCoverPath.SaveAs(fullPath);

            Album model = new Album
            {
                A_Title = txtTitle.Text,
                A_Detail = txtDetail.Text,
                A_CoverPath = fileName,
                A_IsPrivate = isPrivate.Checked,
                A_CreateDate = DateTime.Now,
                U_Id = CurrentUser.U_Id,
                A_Id = Guid.NewGuid().ToString()
            };

            if (Album.CreateOrUpdate(model))
            {
                Response.Redirect("AlbumManager.aspx");
            }
        }
    }
}